Page({
  /**
   * 页面的初始数据
   */
  data:{
    id: wx.getStorageSync('id'),
    password: wx.getStorageSync('password'),
    user: wx.getStorageSync('user'),
  },
  input_id: function (e) {
    this.setData({
      id: e.detail.value
    })
  },
  input_password: function (e) {
    this.setData({
      password: e.detail.value
    })
  },

  show:function(){
  },

  getUserTo: function (that, id) {
    wx.request({
      url: 'http://121.4.60.73:8080/wechat/getWeChatUserById',
      method: 'GET',
      header: { 'content-type': 'application/json' },
      data: {
        'id': id,
      },
      success:(res) => {
        var user = JSON.stringify(res.data);
        wx.setStorageSync('user', user)
        wx.navigateTo({
          url: '/pages/questionnaire/questionnaire?user=' + user,
        })
      },
    })
  },

  submitButtom: function () {
    var that = this;
    wx.request({
      url: 'http://121.4.60.73:8080/wechat/judgeWeChatUser',
      method: 'GET',
      header: { 'content-type': 'application/json' },
      data: {
        'id': that.data.id,
        'password': that.data.password
      },
      success: function (res) {
        var resData = res.data;
        wx.setStorageSync('id', that.data.id)
        wx.setStorageSync('password', that.data.password)
        if (resData == true) {
          that.getUserTo(that, that.data.id);
        } else {
          wx.showToast({
            title: '登录失败',
            image: '/images/no.png',
            duration: 2000
          })
        }
      }

    }) 

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that=this
    // if(that.data.user != ''){
    //   wx.navigateTo({
    //     url: '/pages/questionnaire/questionnaire?user=' + that.data.user,
    //   })
    // }
    // this.submitButtom()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})